home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / gfx / x11 / x3270_3_2_16.lha / amiga_src / xio.c < prev    next >
C/C++ Source or Header  |  2008-10-18  |  3KB  |  127 lines

  1. /*
  2.  * Modifications Copyright 1993, 1994, 1995, 1996, 1999, 2000 by Paul Mattes.
  3.  * Original X11 Port Copyright 1990 by Jeff Sparkes.
  4.  *  Permission to use, copy, modify, and distribute this software and its
  5.  *  documentation for any purpose and without fee is hereby granted,
  6.  *  provided that the above copyright notice appear in all copies and that
  7.  *  both that copyright notice and this permission notice appear in
  8.  *  supporting documentation.
  9.  *
  10.  * Copyright 1989 by Georgia Tech Research Corporation, Atlanta, GA 30332.
  11.  *  All Rights Reserved.  GTRC hereby grants public use of this software.
  12.  *  Derivative works based on this software must incorporate this copyright
  13.  *  notice.
  14.  */
  15.  
  16. /*
  17.  *    xio.c
  18.  *        Low-level I/O setup functions and exit code.
  19.  */
  20.  
  21. #include "globals.h"
  22.  
  23. #include "actionsc.h"
  24. #include "hostc.h"
  25. #include "telnetc.h"
  26. #include "togglesc.h"
  27. #include "utilc.h"
  28. #include "xioc.h"
  29.  
  30. /* Statics. */
  31. static unsigned long ns_read_id;
  32. static unsigned long ns_exception_id;
  33. static Boolean reading = False;
  34. static Boolean excepting = False;
  35.  
  36. /*
  37.  * Called to set up input on a new network connection.
  38.  */
  39. void
  40. x_add_input(int net_sock)
  41. {
  42.     ns_exception_id = AddExcept(net_sock, net_exception);
  43.     excepting = True;
  44.     ns_read_id = AddInput(net_sock, net_input);
  45.     reading = True;
  46. }
  47.  
  48. /*
  49.  * Called when an exception is received to disable further exceptions.
  50.  */
  51. void
  52. x_except_off(void)
  53. {
  54.     if (excepting) {
  55.         RemoveInput(ns_exception_id);
  56.         excepting = False;
  57.     }
  58. }
  59.  
  60. /*
  61.  * Called when exception processing is complete to re-enable exceptions.
  62.  * This includes removing and restoring reading, so the exceptions are always
  63.  * processed first.
  64.  */
  65. void
  66. x_except_on(int net_sock)
  67. {
  68.     if (excepting)
  69.         return;
  70.     if (reading)
  71.         RemoveInput(ns_read_id);
  72.     ns_exception_id = AddExcept(net_sock, net_exception);
  73.     excepting = True;
  74.     if (reading)
  75.         ns_read_id = AddInput(net_sock, net_input);
  76. }
  77.  
  78. /*
  79.  * Called to disable input on a closing network connection.
  80.  */
  81. void
  82. x_remove_input(void)
  83. {
  84.     if (reading) {
  85.         RemoveInput(ns_read_id);
  86.         reading = False;
  87.     }
  88.     if (excepting) {
  89.         RemoveInput(ns_exception_id);
  90.         excepting = False;
  91.     }
  92. }
  93.  
  94. /*
  95.  * Application exit, with cleanup.
  96.  */
  97. void
  98. x3270_exit(int n)
  99. {
  100.     static Boolean already_exiting = 0;
  101.  
  102.     /* Handle unintentional recursion. */
  103.     if (already_exiting)
  104.         return;
  105.     already_exiting = True;
  106.  
  107.     /* Turn off toggle-related activity. */
  108.     shutdown_toggles();
  109.  
  110.     /* Shut down the socket gracefully. */
  111.     host_disconnect(False);
  112.  
  113.     /* Tell anyone else who's interested. */
  114.     st_changed(ST_EXITING, True);
  115.  
  116.     exit(n);
  117. }
  118.  
  119. void
  120. Quit_action(Widget w, XEvent *event, String *params, Cardinal *num_params)
  121. {
  122.     action_debug(Quit_action, event, params, num_params);
  123.     if (!w || !CONNECTED) {
  124.         x3270_exit(0);
  125.     }
  126. }
  127.